package com.walk.zworld.api.http;

import android.app.Activity;
import android.content.Context;
import android.view.View;


import io.reactivex.Observable;

public class JumpInterceptor {
  public static Observable<Boolean> shouldInterceptor(Context context) {
      if (!CommonAppConfig.isLogin()){
//           RouteUtil.forwardLogin();
           return Observable.just(false);
      }
      return null;
  }

  public static void shouldInterceptor(int code){
      if(!canClick()){
          return;
      }
      if(code==BaseHttpCallBack.NO_LOGIN||code==BaseHttpCallBack.EXPIRE_LOGIN||code==BaseHttpCallBack.LOGIN_ERROR){
          interceptorAndFinshActivity();
      }
  }

    private static long sLastClickTime;
    public static boolean canClick() {
        long curTime = System.currentTimeMillis();
        if (curTime - sLastClickTime < 500) {
            return false;
        }
        sLastClickTime = curTime;
        return true;
    }
    public static <T> T getTag(View v, Class<T>cs) {
        Object object=v.getTag();
        if(object!=null&&object.getClass()==cs){
            T t= (T) object;
            return t;
        }
        return null;
    }

    public static void interceptorAndFinshActivity(){
//      Activity activity= ActivityMannger.getInstance().getMainStackTopActivity();
//      boolean isBaseActivity=ActivityMannger.getInstance().isBaseActivity(activity);
//      if(activity!=null&&!isBaseActivity&&!activity.isFinishing()){
//         activity.finish();
//      }
//       RouteUtil.forwardLogin();
    }


}
